<template>
  <div class="combo">
    <div class="combo-title">
      <span
        >{{ data.name
        }}<i class="el-icon-remove-outline" @click="closeCombo(data)"></i
      ></span>
    </div>
    <transition name="fade" v-for="(item, index) in data.child" :key="index">
      <ComboList v-if="item.child.length > 0 && !item.collapsed" :data="item" @clickNode="clickNode" />
      <NodeList v-else :nodeData="item" @extendNode="extendNode" @clickNode="clickNode" />
    </transition>
  </div>
</template>

<script>
import ComboList from "./ComboList.vue";
import NodeList from "./NodeList.vue";
export default {
  name: "ComboList",
  props: {
    data: {
      type: Object,
      default: {},
    },
  },
  components: {
    ComboList,
    NodeList,
  },
  data() {
    return {};
  },
  mounted() {},
  methods: {
    extendNode(data) {
      data.collapsed = false;
    },
    closeCombo(data) {
      data.collapsed = true;
    },
    clickNode(code) {
      this.$emit("clickNode", code);
    },
  },
};
</script>

<style lang="scss" scoped>
.fade-enter-active {
  transition: width 0.5s, height 0.5s;
}
.fade-enter {
  width: 0;
  height: 0;
}
.combo {
  border: 1px solid #94aaeb;
  position: relative;
  min-width: 50px;
  min-height: 50px;
  margin-bottom: 10px;
  margin-right: 10px;
  border-radius: 8px;
  padding: 20px 10px 0 20px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  align-content: center;
  width: 100%;
  .combo-title {
    position: absolute;
    width: 100%;
    top: -8px;
    left: 0;
    font-size: 12px;
    text-align: center;
    height: 16px;
    line-height: 16px;
    span {
      display: inline-block;
      padding: 0 6px;
      background: #fff;
      i {
        margin-left: 4px;
        font-size: 14px;
      }
    }
  }
}
</style>